import 'dart:async';
import 'dart:math';

import 'package:flutter/material.dart';

class RedDot extends StatefulWidget {
  const RedDot({Key? key}) : super(key: key);

  @override
  State<RedDot> createState() => _RedDotState();
}

class _RedDotState extends State<RedDot> with TickerProviderStateMixin {
  double _w = 40;
  double _h = 40;
  double _border = 20;
  double w = 40;
  double h = 40;
  late AnimationController animationController;
  double a = 0;

  @override
  void initState() {
    animationController = AnimationController(
      vsync: this,
      lowerBound: 0,
      upperBound: 1,
      duration: const Duration(seconds: 1),
    )
      ..addListener(() {
        setState(() {
          a = animationController.value;
        });
      })
      ..addStatusListener((status) {
        print('addStatusListener $status');
        if (status == AnimationStatus.completed) {
          animationController.repeat();
        }
      });
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      animationController.forward();
    });
  }

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: 60,
      height: 60,
      child: Stack(
        alignment: Alignment.center,
        children: [
          Container(
            alignment: Alignment.center,
            width: _w + _border * a,
            height: h + _border * a,
            decoration: BoxDecoration(
                shape: BoxShape.circle,
                color: Colors.red.withOpacity(max(0, 0.9 - a))),
          ),
          Container(
            width: 40,
            height: 40,
            decoration:
                const BoxDecoration(shape: BoxShape.circle, color: Colors.red),
          ),
        ],
      ),
    );
  }
}
